package com.travelgroup.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.travelgroup.constant.RedisConstant;
import com.travelgroup.domain.entity.Activity;
import com.travelgroup.mapper.ActivityMapper;
import com.travelgroup.service.IActivityService;
import com.travelgroup.utils.RedisUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity>
        implements IActivityService {
    @Resource
    private RedisUtil redisUtil;

    /**
     * 行程id查询活动信息
     * @param scheduleId
     * @return
     */
    @Override
    public List<Activity> getActivitiesByRedis(Long scheduleId) {
        return redisUtil.queryListById(RedisConstant.ACTIVITY_KEY, scheduleId, Activity.class,
                i -> this.lambdaQuery()
                        .eq(Activity::getScheduleId, i).list(),
                RedisConstant.CACHE_TTL, TimeUnit.MINUTES);
    }
}
